<?php

namespace App\Entities;

use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;

class Module extends Model implements Transformable
{
    use TransformableTrait;

    public $table = 'modules';

    protected $fillable=[
        'name','list','article','cover',
    ];

    protected $dates = ['deleted_at'];

    protected static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub

        //删除关联category
        self::deleted(function($model){
            $model->categories()->detach();
        });
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function categories(){
        return $this->belongsToMany('App\Entities\Category', 'categories');
    }
}
